package com.xy.exam.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.xy.exam.pojo.dto.ExamAddNewDTO;
import com.xy.exam.pojo.dto.ExamUpdateDTO;

import com.xy.exam.pojo.dto.FrontCheckResultExamDTO;
import com.xy.exam.pojo.vo.ExamStandardVO;
import com.xy.exam.pojo.vo.FrontCheckResultExamVO;
import com.xy.exam.service.IExamService;

import com.xy.exam.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@Slf4j
@RequestMapping("/exam")
@RestController
@Api(tags="03.考试管理")//添加模块名称
public class ExamController {
    @Autowired
    IExamService examService;
    @PostMapping("/add-new")
    @ApiOperation(value = "添加考试")//添加名称
    @ApiOperationSupport(order = 100)//排序
    public JsonResult addNew(ExamAddNewDTO examAddNewDTO) {
        examService.addNew(examAddNewDTO);
        return new JsonResult().ok();
    }




    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("删除考试,根据id")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "考试ID", required = true, dataType = "long")
    })
    public JsonResult delete(@Range(min = 1, message = "删除考试失败，ID值无效！")
                             @PathVariable Long id) {
        examService.delete(id);
        return JsonResult.ok();
    }


    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改考试")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "考试ID", required = true, dataType = "long")
    })
    public JsonResult updateExamById(@Range(min = 1, message = "修改考试失败，ID值无效！")
                                     @PathVariable Long id, @Valid ExamUpdateDTO examUpdateDTO) {
        examService.updateExamById(id,examUpdateDTO);
        return JsonResult.ok();
    }
    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("查询相册详情,根据id")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "考试ID", required = true, dataType = "long")
    })
    public JsonResult getStandardById(@Range(min = 1, message = "获取考试失败，ID值无效！")
                                      @PathVariable Long id) {
        ExamStandardVO standardById = examService.getStandardById(id);
        return JsonResult.ok(standardById);
    }
    @GetMapping("/list")
    @ApiOperation("查询考试列表")
    @ApiOperationSupport(order = 420)
    public JsonResult list() {
        return JsonResult.ok(examService.list());
    }


    @PostMapping("/checkResult")
    @ApiOperation("查询成绩")
    @ApiOperationSupport(order = 420)
    public JsonResult checkResult(FrontCheckResultExamDTO frontCheckResultExamDTO) {
        FrontCheckResultExamVO resultExamVO = examService.checkResult(frontCheckResultExamDTO);
        return JsonResult.ok(resultExamVO);
    }


}
